package stat;

import com.xeiam.xchart.Chart;
import com.xeiam.xchart.StyleManager;
import tsd.TSD;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * Author: Oleg Yasnev (oyasnev@gmail.com)
 * Date: 24.05.14
 */
public class TSDConservChart extends TSDStatChart {

    public TSDConservChart(int locX, int locY) {
        super(locX, locY);
        chartHeader = "TSD conservativity (edit distance)";
        chartTitle  = "TSD conservativity (edit distance)";
        xTitle      = "Edit distance";
        yTitle      = "Count";
        seriesName  = "TSD conservativity";
    }

    @Override
    protected void updateData(List<TSD> tsdList) {
        Map<Integer, Integer> map = new TreeMap<Integer, Integer>();
        for (TSD tsd : tsdList) {
            if (tsd.hasTSD) {
                int dist = tsd.dist;
                int count = map.containsKey(dist) ? map.get(dist) : 0;
                map.put(dist, count + 1);
            }
        }

        xData.clear();
        yData.clear();
        for (Integer x : map.keySet()) {
            xData.add(x * 1.0);
            yData.add(map.get(x) * 1.0);
        }
    }

    @Override
    protected Chart getChart() {
        Chart chart = super.getChart();
        chart.getStyleManager().setChartType(StyleManager.ChartType.Bar);
        return chart;
    }
}
